package cn.xt.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author ifdestiny
 * @create 2018-11-24 15:02
 */

public class DateConverter {
	private static final DateFormat[] dfs = { 
			new SimpleDateFormat("yyyy 年MM 月dd 日"),
			new SimpleDateFormat("yyyy-MM-dd"),
			new SimpleDateFormat("MM/dd/yy"),
			new SimpleDateFormat("yyyy.MM.dd"), 
			new SimpleDateFormat("yyMMdd"),
			new SimpleDateFormat("yyyy/MM/dd") };

	public static Date convertFromString( String value) {
		for(int i=0;i<dfs.length;i++){
			try {
				return dfs[i].parse(value);
			} catch (ParseException e) {
				continue;
			}
		}
		throw new ClassCastException ("类型转换错误；");
	}

	public static String convertToString( Date dateTime) {
	
		Date date = dateTime;
		
		return new SimpleDateFormat("yyyy-MM-dd").format(date);
	}

}
